#ifndef __SEG_LCD_H_H_
#define __SEG_LCD_H_H_

#include "stdint.h"

#ifdef __cplusplus
extern "C"
{
#endif

#define seg_lcd_bit4_make(seg, com) ((seg << 2) + com)
#define seg_lcd_bit8_make(seg, com) ((seg << 3) + com)

#define SEG_MAKE seg_lcd_bit4_make
#define PTR_SEG_RAM ((uint8_t *)(seg_lcd_buff))

#define slcd_bit_set(x) PTR_SEG_RAM[x >> 3] |= 1 << (x & 0x07)
#define slcd_bit_get(x) ((PTR_SEG_RAM[x >> 3] >> (x & 0x07)) & 1)
#define slcd_bit_clr(x) PTR_SEG_RAM[x >> 3] &= ~(1 << (x & 0x07))
#define slcd_bit_tog(x) PTR_SEG_RAM[x >> 3] ^= 1 << (x & 0x07)

#define mseg_lcd_bit4_make(ic, seg, com) ((ic << 7) + (seg << 2) + com)

#define mlcd_bit_set(x) PTR_SEG_RAM[x >> 7][(x >> 3) & 15].val |= 1 << (x & 0x07)
#define mlcd_bit_get(x) ((PTR_SEG_RAM[x >> 7][(x >> 3) & 15].val >> (x & 0x07)) & 1)
#define mlcd_bit_clr(x) PTR_SEG_RAM[x >> 7][(x >> 3) & 15].val &= ~(1 << (x & 0x07))
#define mlcd_bit_tog(x) PTR_SEG_RAM[x >> 7][(x >> 3) & 15].val ^= 1 << (x & 0x07)

#define SEG_ORG_NONE SEG_MAKE(0, 0)

#define SEG_APP_NONE SEG_ORG_NONE

#define SEG_LCD_ENV_VAR

	extern uint8_t *seg_lcd_buff;

#define LED_SEG_STRUCT

	typedef union
	{
		uint8_t val;
		struct
		{
			uint8_t A : 1;
			uint8_t B : 1;
			uint8_t C : 1;
			uint8_t D : 1;
			uint8_t E : 1;
			uint8_t F : 1;
			uint8_t G : 1;
			uint8_t DP : 1;
		} seg;
	} led_seg_type;

#define SEG_LCD_SEG_RAM_STR

union slcd_ram_com4_str
{
	uint8_t val;
	
	struct
	{
		uint8_t LCOM0 : 1;
		uint8_t LCOM1 : 1;
		uint8_t LCOM2 : 1;
		uint8_t LCOM3 : 1;
		uint8_t HCOM0 : 1;
		uint8_t HCOM1 : 1;
		uint8_t HCOM2 : 1;
		uint8_t HCOM3 : 1;
	} bits;
};

union slcd_ram_com8_str
{
	uint8_t val;
	
	struct
	{
		uint8_t COM0 : 1;
		uint8_t COM1 : 1;
		uint8_t COM2 : 1;
		uint8_t COM3 : 1;
		uint8_t COM4 : 1;
		uint8_t COM5 : 1;
		uint8_t COM6 : 1;
		uint8_t COM7 : 1;
	} bits;
};

typedef union slcd_ram_com4_str slcd_ram_com4_type;
typedef union slcd_ram_com8_str slcd_ram_com8_type;

#define SEG_LCD_SEG_NUM_STR

	struct seg_num_bits_make_str
	{
		uint8_t dp_en;
		uint8_t bit_A;
		uint8_t bit_B;
		uint8_t bit_C;
		uint8_t bit_D;
		uint8_t bit_E;
		uint8_t bit_F;
		uint8_t bit_G;
		uint8_t bit_DP;
	};

	typedef struct seg_num_bits_make_str seg_num_bits_make_type;

#define SEG_LCD_ENV_API

	void seg_lcd_buff_set(uint8_t *buff);
	void seg_lcd_num_cfg_set(const seg_num_bits_make_type *cfg, uint8_t *num_old);
	void seg_lcd_num_set(uint8_t site, uint8_t val);

#ifdef __cplusplus
}
#endif

#endif 
